package sf.database.dialect.db2;

import com.querydsl.sql.DB2Templates;
import com.querydsl.sql.SQLTemplates;
import org.jooq.SQLDialect;
import sf.database.dialect.DBDialect;
import sf.database.dialect.DatabaseDriver;
import sf.database.meta.TableMapping;
import sf.database.support.RDBMS;

import java.sql.Connection;

public class DB2Dialect extends DBDialect {
    @Override
    public DatabaseDriver getDatabaseDriver() {
        return DatabaseDriver.DB2;
    }

    @Override
    public RDBMS getName() {
        return null;
    }

    @Override
    public String getHibernateDialect() {
        return null;
    }

    @Override
    public String sqlTableDrop(String table) {
        return null;
    }

    @Override
    public String sqlTableRename(String oldName, String newName) {
        return null;
    }

    @Override
    public String sqlColumnAdd(String table, String column_definition, String column_position) {
        return null;
    }

    @Override
    public String sqlColumnModify(String table, String column_definition, String column_position) {
        return null;
    }

    @Override
    public String sqlColumnDrop(String table, String column) {
        return null;
    }

    @Override
    public boolean createEntity(Connection conn, TableMapping en) {
        return false;
    }

    @Override
    public String uniqueSql(String tableName, String name, String[] columnNames) {
        return null;
    }

    @Override
    public String sqlPageList(String sql, long offset, int limit) {
        long pageEnd = offset + limit - 1;

        int capacity = sql.length() + 180;
        StringBuilder builder = new StringBuilder(capacity);
        builder.append(" SELECT * FROM ").append("(");
        builder.append("	SELECT inner_query_b.*, ROWNUMBER() OVER() beetl_rn  FROM   ");
        builder.append("	(   ").append(sql).append("	) AS inner_query_b  ");
        builder.append(" )AS inner_query_a WHERE inner_query_a.beetl_rn BETWEEN ");
        builder.append(offset).append(" and ").append(pageEnd);

        return builder.toString();
    }

    @Override
    public SQLTemplates getQueryDslDialect() {
        return DB2Templates.DEFAULT;
    }

    @Override
    public SQLDialect getJooqDialect() {
        return null;
    }
}
